package com.rg.servlet;

import com.rg.model.GoodsModel;
import com.rg.model.OrderModel;
import com.rg.service.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/deleteGoodsCartServlet")
public class deleteGoodsCartServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer goodsid=Integer.valueOf(request.getParameter("goodsid"));
        OrderModel order=(OrderModel)request.getSession().getAttribute("order") ;
        order.deleteGoods(goodsid);
        response.setContentType("application/json;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        PrintWriter out =response.getWriter();
        String jsonstr=null;
        jsonstr="{\"code\":203,\"msg\":\"success\"}";
        out.println(jsonstr);
        out.flush();
        out.close();
    }
}
